#include "http/http.h"

void getIndex(HTTPRequest *request, HTTPResponse *response) {
    const char *indexPath = "web\\dist\\index.html";
    handleStaticFile(indexPath, request, response);
}

void getPublicResources(HTTPRequest *request, HTTPResponse *response) {
    handleStaticResourceDir("web\\dist", request, response);
}

void postIndex(HTTPRequest *request, HTTPResponse *response) {
    const unsigned long contentLength = getContentLength(&request->headers);
    char body[contentLength + 1];
    seekRequestBody(request, 0);

    const auto readSize = readBodyFromRequest(request, body, contentLength);
    printf("readSize: %zu\n", readSize);
    if (readSize != contentLength) {
        response->code = HTTP_INTERNAL_SERVER_ERROR;
    } else {
        body[contentLength] = '\0';
        makeTextResponse(response, body, contentLength);
    }
}